<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			function fun(n){
				var num1=document.getElementById("num1").value;
				var num2=document.getElementById("num2").value;
				if(isNaN(num1)|| isNaN(num2)){
					alert("输入的数字不合法!")
					return;
				}
				if(n==1){
					res=(num1-0)+(num2-0);
				}
				if(n==2){
					res=(num1-0)-(num2-0);
				}
				if(n==3){
					res=(num1-0)*(num2-0);
				}
				if(n==4){
					res=(num1-0)/(num2-0);
				}
				document.getElementById("res").value=res;
			}
		</script>
	</head>
	<body>
		
		第一个数：<input type="text" id="num1" /><br />
		第二个数：<input type="text" id="num2" /><br />
		<button onclick="fun(1)">+</button>
		<button onclick="fun(2)">-</button>
		<button onclick="fun(3)">*</button>
		<button onclick="fun(4)">/</button><br />
		计算结果：<input type="text" id="res" /><br />
	</body>
</html>
